#pragma once

#include "Session.h"
#include <set>
#include <vector>
#include <mutex>

namespace wsbus {

	class Dispatcher
	{
	public:
		Dispatcher() = default;
		Dispatcher(const Dispatcher&) = delete;
		Dispatcher& operator=(const Dispatcher&) = delete;

		void add(SessionParentPtr sessionParent);
		void del(SessionParentPtr sessionParent);
		int deliver(const PackagePtr &msg);
		int broadcast(int fromSessionId, const PackagePtr &msg);
		void broadcastNodeInfo();
		bool existSessionId(unsigned short sessionId) const;

	private:
		mutable std::mutex mutex_;
		std::set<SessionParentPtr> sessions_;
	};

}

